package com.atguigu.vodtest;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.List;


public class TetsVod {

    public static void main(String[] args) throws Exception{
        //根据视频id获取视频播放凭证
        //创建初始化对象
        DefaultAcsClient client = InitObject.initVodClient("LTAI4GAa1k68JkqHmrgVpfKG", "kTovjBoIu0sqie4yZmHGP5rIazXuuC");
        //创建获取视频地址request和response
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        //向request对象里面设置视频id。
        request.setVideoId("0712027b7d6d424bb77f98894ae6171b");
        //调用初始化对象里面的方法得到凭证
        response = client.getAcsResponse(request);

            System.out.println("playAuth："+response.getPlayAuth());

    }

    //根据视频id获取视频播放地址的方法
    public static void getPlayUrl() throws Exception{
        //根据视频id获取视频的播放地址
        //创建初始化对象（初始化客户端、请求对象和相应对象）（参数是oss的两个）
        DefaultAcsClient client = InitObject.initVodClient("LTAI4GAa1k68JkqHmrgVpfKG", "kTovjBoIu0sqie4yZmHGP5rIazXuuC");
        //创建获取视频地址request和response
        GetPlayInfoRequest request=new GetPlayInfoRequest();
        GetPlayInfoResponse response=new GetPlayInfoResponse();
        //向request对象里面设置视频id。设置请求参数(注意：这里只能获取非加密视频的播放地址)
        request.setVideoId("0712027b7d6d424bb77f98894ae6171b");

            //调用初始化对象里面的方法传递request，获取数据（获取请求响应）
            response = client.getAcsResponse(request);

            //输出请求结果（从结果获取数据）
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() +
                        "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");

    }
}
